package cn.lg.soar.system.auth.model;

import cn.lg.soar.common.model.base.TreeDTO;
import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.system.auth.entity.Role;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Set;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class RoleDto extends TreeDTO {

    public final static BeanCopier<RoleDto, Role> TO_ENTITY = BeanCopier.create(RoleDto.class, Role.class);
    public final static BeanCopier<Role, RoleDto> FROM_ENTITY = BeanCopier.create(Role.class, RoleDto.class);

    @NotNull(message = "id不能为空", groups = {Update.class})
    @Min(value = 0, message = "id不能小于0", groups = {Update.class})
    @ApiModelProperty(value = "主键id")
    private Long id;

    @NotBlank(message = "角色编码不能为空", groups = {Create.class})
    private String code;

    private Integer type;

    @NotBlank(message = "角色名不能为空", groups = {Create.class})
    private String name;

    private String alias;

    @ApiModelProperty(value = "备注")
    private String remark;

    private Set<Long> menuIds;

    public RoleDto() {
    }

    public RoleDto(Role data) {
        FROM_ENTITY.copy(data, this);
    }

    public Role toRole() {
        return TO_ENTITY.convert(this);
    }
}
